#!/usr/bin/python

#BEEF WELLINGTON inc.
#DATA PROCESSOR SHELL 1.0.4, API 2.7.5
#copyleft by Beef Wellington inc.
#reproduction of the shell application is allowed
#this application is only for unix based systems    
#beef wellington inc will require windows batch developement for setup file                                                                                                          

#import modules
import sys
import dataProcess as d

#create commands
commands = ["prcs", "retp", "extp", "savn", "txtc"]

#title screen
print("\n>>>> D A T A    P R O C E S S O R <<<<")
print("shell 1.0.4, API 2.7.5")
print("\nthis program is copyleft software made for Linux\ncopyleft by Beef Wellington inc.\nreproduction of the shell application is allowed\n")

#main loop
while True:
    anInput = str(raw_input("~# "))
    #expected input:
    #~# prcs@test.txt
    if anInput == "quit":
	print("")
        break
    elif anInput == "help":
        print("prcs@{enter a file to process, any file extension}\nretp@{enter a .fubr file with processed data to print out data}\nextp@{a .fubr file with processed data to split into two files, database and statistics}\nsavn@{the .fubr file from which the data is recieved}&{the new file in which the data is written},\ntxtc@{a .fubr file with data raw data needed to be converted into text}&{new extension for new files}")
    elif anInput == "":
        continue
    else:
        try:
            anInput = anInput.split("@")
        except:
            print("error : CANNOT PARSE COMMAND")
            continue
            #break
            #sys.exit()
        try:
            command = anInput[0]
            parameter = anInput[1]
        except:
            print("error : CANNOT PARSE COMMAND")
            continue
        #TEST 
        #print(command)
        #print(parameter)
        if command not in commands:
            print("error : UNKNOWN COMMAND")
            continue
            #break
            #sys.exit()
        else:
            if command == commands[0]:
                fileN = parameter.split(".")[0]
                try:
                    d.process(parameter, fileN, False, True)
                except:
                    print("> CANNOT PROCESS DATA")
                    continue
                print("restart the shell by relaunching the shell.py file")
                break
            elif command == commands[1]:
                print("\n")
                try:
                    d.Archive.prints(parameter)
                except:
                    print("> CANNOT OUTPUT DATA")
                    continue
            elif command == commands[2]:
                try:
                    d.Archive.extract(parameter, "extData")
                except:
                    print("> CANNOT EXTRACT DATA")
                    continue
            elif command == commands[3]:
                params = parameter.split("&")
                mainFile = params[0]
                newFile = params[1]
                try:
                    d.Archive.save(mainFile, newFile)
                except:
                    print("> CANNOR REWRITE THE DATA TO NEW FILE")
                    continue
            elif command == commands[4]:
                params = parameter.split("&")
                mainFile = params[0]
                exten = params[1]
                try:
                    d.Archive.dTextConvert(mainFile, exten)
                except:
                    print("> CANNOT PERFORM DATA CONVERION")
                    continue
            else:
                print("error : UNKNOWN COMMAND")
                continue
                #break
                #sys.exit()
sys.exit()
